package com.module.frame.dialog;

import android.content.Context;

/**
 * @author bsnl_yanxuwen
 * @date 2021/1/21 11:25
 * Description :
 * 通用加载框。
 * 这里不创建加载框，使用代理，将创建在在代理类创建
 */
public class LoadingDialogUtils {

    private static Class<? extends ILoadingDialogImpl> className;
    ILoadingDialogImpl impl;

    public void show(Context context) {
        if (getImpl() != null && context != null) {
            getImpl().show(context);
        }
    }

    public void hide() {
        if (getImpl() != null) {
            getImpl().hide();
        }
    }

    public void destroy() {
        if (getImpl() != null) {
            getImpl().destroy();
        }
    }


    public static void setDialogImpl(Class<? extends ILoadingDialogImpl> myClassName) {
        className = myClassName;
    }

    private ILoadingDialogImpl getImpl() {
        if (impl == null) {
            try {
                impl = className.newInstance();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            }
        }
        return impl;
    }


}
